import Login from './views/Login.vue'
import NotFound from './views/404.vue'
import Home from './views/Home.vue'
import Main from './views/Main.vue'
import Table from './views/nav1/Table.vue'
import Form from './views/nav1/Form.vue'
import user from './views/nav1/user.vue'
import Page4 from './views/nav2/Page4.vue'
import Page5 from './views/nav2/Page5.vue'
import Page6 from './views/nav3/Page6.vue'
import echarts from './views/charts/echarts.vue'



import Department from './views/org/Department.vue'
import Employee from './views/org/Employee.vue'
import Shop from './views/org/Shop.vue'
import DicType from "./views/org/DicType";
import ShopRegister from "./views/ShopRegister.vue";
import PetSearchMasterMSG from "./views/pet/PetSearchMasterMSG.vue";
import Pet from "./views/pet/Pet.vue";
import UptShopRegister from "./views/UptShopRegister.vue";
import Product from "./views/product/Product.vue";
import axios from "axios";


let routes = [
    {
        path: '/uptShopRegister',
        component: UptShopRegister,
        name: '',
        hidden: true
    },
    {
        path: '/shopreg',
        component: ShopRegister,
        name: '',
        hidden: true
    },
    {
        path: '/login',
        component: Login,
        name: '',
        hidden: true
    },
    {
        path: '/404',
        component: NotFound,
        name: '',
        hidden: true
    },
    {
        path: '/',
        component: Home,
        name: '系统设置',
        iconCls: 'el-icon-message',//图标样式class
        children: [
            { path: '/form1', component: Form, name: '角色管理' },
            { path: '/user1', component: user, name: '系统菜单' },
            { path: '/user2', component: user, name: '系统日志' },
            { path: '/dicType', component: DicType, name: '数据字典' },
            { path: '/user4', component: user, name: '系统参数' },
        ]
    },
    {
        path: '/',
        component: Home,
        name: '组织机构',
        iconCls: 'el-icon-message',//图标样式class
        children: [
            { path: '/dept', component: Department, name: '部门管理' },
            { path: '/emp', component: Employee, name: '员工管理' },
            { path: '/shop', component: Shop, name: '商铺管理' },
        ]
    },
    {
        path: '/',
        component: Home,
        name: '宠物管理',
        iconCls: 'el-icon-message',//图标样式class
        children: [
            { path: '/petPSM', component: PetSearchMasterMSG, name: '宠物寻主' },
            { path: '/pet', component: Pet, name: '宠物领养' },
        ]
    },
    {
        path: '/',
        component: Home,
        name: '服务管理',
        iconCls: 'el-icon-message',//图标样式class
        children: [
            { path: '/product', component: Product, name: '服务列表' },
        ]
    },
    //{ path: '/main', component: Main },
    {
        path: '/',
        component: Home,
        name: '导航一',
        iconCls: 'el-icon-message',//图标样式class
        children: [
            { path: '/main', component: Main, name: '主页', hidden: true },
            { path: '/table', component: Table, name: 'Table' },
            { path: '/form', component: Form, name: 'Form' },
            { path: '/user', component: user, name: '列表' },
        ]
    },
    {
        path: '/',
        component: Home,
        name: '导航二',
        iconCls: 'fa fa-id-card-o',
        children: [
            { path: '/page4', component: Page4, name: '页面4' },
            { path: '/page5', component: Page5, name: '页面5' }
        ]
    },
    {
        path: '/',
        component: Home,
        name: '',
        iconCls: 'fa fa-address-card',
        leaf: true,//只有一个节点
        children: [
            { path: '/page6', component: Page6, name: '导航三' }
        ]
    },
    {
        path: '/',
        component: Home,
        name: 'Charts',
        iconCls: 'fa fa-bar-chart',
        children: [
            { path: '/echarts', component: echarts, name: 'echarts' }
        ]
    },
    {
        path: '*',
        hidden: true,
        redirect: { path: '/404' }
    }
];

export default routes;


// http request 请求拦截器
axios.interceptors.request.use(
    config => {
        const token = localStorage.getItem('TOKEN')
        if (token) { // 判断是否存在token，如果存在的话，则每个http header都加上token
            // 请求头加上token
            //config.headers.authorization = token
            config.headers['U-TOKEN'] = token;
        }
        console.debug(config)
        //debugger;
        return config;
    },
    err => {
        return Promise.reject(err);
    })

// http response 响应拦截器
axios.interceptors.response.use(
    response => {
        //拦截响应，做统一处理
        //  如果success = false && message = noAuth
        if (!response.data.success && response.data.message === "noAuth") {
            //debugger;
            //  跳转到登录页面
            location.href = "http://127.0.0.1:8081/#/login";
        }
        //  相当于后台的拦截器放行
        return response;
    },
    //接口错误状态处理，也就是说无响应时的处理
    error => {
        // 返回接口返回的错误信息
        return Promise.reject(error.response.status);
    })


